package com.ruoyi.web.controller.weiriya;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.weiriya.domain.WArea;
import com.ruoyi.weiriya.domain.WVehicleChargeType;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weiriya.domain.WVehicleNonChargeType;
import com.ruoyi.weiriya.service.IWVehicleNonChargeTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 车辆非充电类型Controller
 * 
 * @author lynn
 * @date 2023-08-01
 */
@Api(tags = "车辆非充电类型管理")
@RestController
@RequestMapping("/weiriya/nonChargeType")
public class WVehicleNonChargeTypeController extends BaseController
{
    @Autowired
    private IWVehicleNonChargeTypeService wVehicleNonChargeTypeService;

    /**
     * 查询车辆非充电类型列表
     */
    @ApiOperation("获取车辆非充电类型列表")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:list')")
    @GetMapping("/list")
    public TableDataInfo list(WVehicleNonChargeType wVehicleNonChargeType)
    {
        startPage();
        List<WVehicleNonChargeType> list = wVehicleNonChargeTypeService.list(wVehicleNonChargeType.queryWrapper());
        return getDataTable(list);
    }

    /**
     * 导出车辆非充电类型列表
     */
    @ApiOperation("导出车辆非充电类型列表")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:export')")
    @Log(title = "车辆非充电类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WVehicleNonChargeType wVehicleNonChargeType)
    {
        List<WVehicleNonChargeType> list = wVehicleNonChargeTypeService.list(wVehicleNonChargeType.queryWrapper());
        ExcelUtil<WVehicleNonChargeType> util = new ExcelUtil<WVehicleNonChargeType>(WVehicleNonChargeType.class);
        util.exportExcel(response, list, "车辆非充电类型数据");
    }

    /**
     * 导入车辆非充电类型列表
     */
    @ApiOperation("导入车辆非充电类型列表")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:import')")
    @Log(title = "车辆非充电类型", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WVehicleNonChargeType> util = new ExcelUtil<WVehicleNonChargeType>(WVehicleNonChargeType.class);
        List<WVehicleNonChargeType> list = util.importExcel(file.getInputStream());
        return success(wVehicleNonChargeTypeService.saveBatch(list));
    }

    /**
     * 获取车辆非充电类型详细信息
     */
    @ApiOperation("获取车辆非充电类型详细")
    @ApiImplicitParam(name = "id", value = "车辆非充电类型ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wVehicleNonChargeTypeService.getById(id));
    }

    /**
     * 新增车辆非充电类型
     */
    @ApiOperation("新增车辆非充电类型")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:add')")
    @Log(title = "车辆非充电类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WVehicleNonChargeType wVehicleNonChargeType)
    {


        return toAjax(wVehicleNonChargeTypeService.saveType(wVehicleNonChargeType));
    }

    /**
     * 修改车辆非充电类型
     */
    @ApiOperation("更新车辆非充电类型")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:edit')")
    @Log(title = "车辆非充电类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WVehicleNonChargeType wVehicleNonChargeType)
    {
        WVehicleNonChargeType byId = wVehicleNonChargeTypeService.getById(wVehicleNonChargeType.getId());
        if(StringUtils.isNotNull(byId) && byId.getTypeValue().equals(wVehicleNonChargeType.getTypeValue())){
            return success();
        }
        List<WVehicleNonChargeType> list = wVehicleNonChargeTypeService.list(wVehicleNonChargeType.queryWrapper());
        if(list.size() > 0){
            throw new ServiceException("类型已存在！");
        }
        return toAjax(wVehicleNonChargeTypeService.updateById(wVehicleNonChargeType));
    }

    /**
     * 删除车辆非充电类型
     */
    @ApiOperation("删除车辆非充电类型")
    @ApiImplicitParam(name = "ids", value = "车辆非充电类型ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:nonChargeType:remove')")
    @Log(title = "车辆非充电类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wVehicleNonChargeTypeService.removeTypeByIds(ids));
    }
}
